package com.cskaoyan.service.admin;

import com.cskaoyan.bean.*;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.model.admin.vo.BashboardVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Zhuqi
 * @Date: 2021/11/29 19:29
 * @Description:
 */
@Service
public class BashboardServiceImpl implements BashboardService {
    @Autowired
    MarketGoodsMapper marketGoods;
    @Autowired
    MarketUserMapper userMapper;
    @Autowired
    MarketGoodsProductMapper productMapper;
    @Autowired
    MarketOrderMapper orderMapper;

    @Override
    public BashboardVO dashboard() {
        //商品数量
        MarketGoodsExample goodsExample = new MarketGoodsExample();
        long goodscount = marketGoods.countByExample(goodsExample);
        //货品数量
        MarketGoodsProductExample productExample = new MarketGoodsProductExample();
        long productcount = productMapper.countByExample(productExample);
        // 订单数量
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        long ordercount = orderMapper.countByExample(marketOrderExample);
        // 用户数量
        MarketUserExample userExample = new MarketUserExample();
        long usercount = userMapper.countByExample(userExample);

        //将数值set到VO中
        BashboardVO bashboardVO = new BashboardVO();
        bashboardVO.setGoodsTotal((int) goodscount);
        bashboardVO.setOrderTotal((int) ordercount);
        bashboardVO.setProductTotal((int) productcount);
        bashboardVO.setUserTotal((int) usercount);
        return bashboardVO;
    }


}
